const shoppingCart = {
  state: {
    items:[{
      item_name:"HUAWEI Mate 30 Pro 5G",
      item_icon:"https://res.vmallres.com/pimages/product/6901443353224/428_428_BBB155FB6C09744712785FB380EA616E967F4F8F8CAEC76Amp.png",
      price:1888,
      count:1,
      id:1,
      checked:false
  },
  
  {
      item_name:"荣耀V30 5G",
      item_icon:"https://res.vmallres.com/pimages/product/6901443356904/428_428_FF89E07076590562DF095FCD47FD0C824121FD0D89A445CEmp.png",
      price:1888,
      count:1,
      id:2,
      checked:false
  },
  {
      item_name:"HUAWEI Mate 30 5G",
      item_icon:"https://res.vmallres.com/pimages/product/6901443353477/428_428_87A0D607385DCA7FD02C11828E0C52D3FC77CEFC0E313D74mp.png",
      price:1888,
      count:1,
      id:3,
      checked:false
  },
  {
      item_name:"荣耀V30 Pro 5G",
      item_icon:"https://res.vmallres.com/pimages/product/6901443356874/428_428_C7D039CACB38EEE8B779FCB548351AF8684A40D153D2704Bmp.png",
      price:1888,
      count:1,
      id:4,
      checked:false
  }],
    allChecked:false
  },
  mutations: {
    //更新商品的选中状态
    updateStoreItemChecked(state,item){
      console.log("==========>",item)
      // 查询购物车中改变选中状态的商品
      state.items.some((element)=>{
        if(element.id === item.id){
          element.checked = item.checked
        }
      })

      //判断购物车中的元素是否是全部被选中，更新全选状态
      var result = state.items.every((element)=>{
        return element.checked === true
      })

      state.allChecked = result;

    },

    updateAllCheckedStatus(state,boolean){
      state.allChecked = boolean;
      state.items.forEach((element)=>{
        element.checked = boolean;
      })
    },

    updateStoreItemCount(state,item){
      state.items.some((element)=>{
        if(element.id === item.id){
          element.count = item.count
        }
      })
    }
  },
  actions: {
    updateStoreItemChecked(context,item){
      context.commit("updateStoreItemChecked",item)
    },

    updateAllCheckedStatus(context,boolean){
      context.commit("updateAllCheckedStatus",boolean);
    },
    updateStoreItemCount(context,item){
      context.commit("updateStoreItemCount",item)
    }
  },
  modules: {
  }
}
export default shoppingCart;